<?php
$imgName = "obraz1.jpg";
$tempDir = "./temp/";

if(isSet($_GET['text']) && isSet($_GET['size']) &&
   isSet($_GET['x']) && isSet($_GET['y'])){
  $text = $_GET['text'];
  $size = $_GET['size'];
  $x = $_GET['x'];
  $y = $_GET['y'];
  if($text == "" || !is_numeric($size) || !is_numeric($x) || !is_numeric($y)){
    die("error\nNieprawidłowe dane.");
  }

  if(!($img = imagecreatefromjpeg($imgName))){
    die("error\nBrak dostępu do obrazu.");
  }

  $white = imagecolorallocate($img, 255, 255, 255);
  $font = "arial.ttf";
  imagettftext($img, $size, 0, $x, $y, $white, $font, $text);

  $imgName = microtime().rand();
  imagejpeg($img, $tempDir.$imgName);
  imagedestroy($img);
  echo $imgName;
}
else{
  if(!($img = imagecreatefromjpeg($imgName))){
    exit();
  }
  header('Content-Type: image/jpeg');
  imagejpeg($img);
  imagedestroy($img);
}
?>
